﻿using System;
using System.Data;
using ContractManagementSystem.DataAccess;
using ContractManagementSystem.Entity;

namespace ContractManagementSystem.BusinessLogic
{
    public static class ContractBusiness
    {
        public static string UserName { get; set; }
        public static string ErrorMessage { get; set; }
        private static ContractDataAccess _contractDataAccess;

        public static bool Insert(ContractEntity contractEntity)
        {
            _contractDataAccess = new ContractDataAccess();
            if (_contractDataAccess.Insert(contractEntity)==1)
            {
                return true;
            }
            ErrorMessage = _contractDataAccess.ErrorMessage;
            return false;
        }

        public static bool Update(ContractEntity contractEntity)
        {
            _contractDataAccess = new ContractDataAccess();
            if (_contractDataAccess.Update(contractEntity) == 1)
            {
                return true;
            }
            ErrorMessage = _contractDataAccess.ErrorMessage;
            return false;
        }

        public static bool Delete(string id)
        {
            _contractDataAccess = new ContractDataAccess();
            if (_contractDataAccess.Delete(id) == 1)
            {
                return true;
            }
            ErrorMessage = _contractDataAccess.ErrorMessage;
            return false;
        }

        public static DataTable FetchAll()
        {
            _contractDataAccess = new ContractDataAccess();
            return _contractDataAccess.FetchAll();
        }

        public static DataTable FetchAllWithContractor(string fullName, string contractTypeId,string startDate,string endDate)
        {
            _contractDataAccess = new ContractDataAccess();
            return _contractDataAccess.FetchAllWithContractor(fullName,contractTypeId,startDate,endDate);
        }

        public static DataTable FetchAllWithContractType(Guid id)
        {
            _contractDataAccess = new ContractDataAccess();
            return _contractDataAccess.FetchAllWithContractType(id);
        }

        public static ContractEntity FetchByContractId(string id)
        {
            _contractDataAccess = new ContractDataAccess();
            return _contractDataAccess.FetchById(id);
        }

        public static DataTable FetchContractDateById(Guid contractId)
        {
            _contractDataAccess = new ContractDataAccess();
            return _contractDataAccess.FetchContractDateById(contractId);
        }

        public static DataTable FetchByContractorId(string id)
        {
            _contractDataAccess = new ContractDataAccess();
            return _contractDataAccess.FetchById("sp_Contract_SelectByContractorId", id);
        }

        public static DataTable FetchByConsultantId(string id)
        {
            _contractDataAccess = new ContractDataAccess();
            return _contractDataAccess.FetchById("sp_Contract_SelectByConsultantId", id);
        }

        public static DataTable FetchByManagerId(string id)
        {
            _contractDataAccess = new ContractDataAccess();
            return _contractDataAccess.FetchById("sp_Contract_SelectByManagerId", id);
        }

        public static DataTable FetchContractIdByUserId(Guid userId)
        {
            _contractDataAccess = new ContractDataAccess();
            return _contractDataAccess.FetchContractIdByUserId(userId);
        }

        public static DataTable FetchContractByKey(Guid contractorId, Guid keyId, char role)
        {
            _contractDataAccess = new ContractDataAccess();
            return _contractDataAccess.FetchContractByKey(contractorId, keyId,role);
        }

        public static DataTable FetchContractorByKey(Guid keyId, char role)
        {
            _contractDataAccess = new ContractDataAccess();
            return _contractDataAccess.FetchContractorByKey(keyId, role);
        }

        public static object FetchAllWithContractor(string fullName)
        {
            throw new NotImplementedException();
        }
    }
}
